package com.jade.store.pay.entity;

import com.jade.bss.db.IdEntity;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 微信支付订单
 * User: JinYa 2009_jinya@163.com
 * Date: 2016-11-2
 * Time: 14:51
 * Version : 1.0
 * Remark:
 * History:
 */
@Entity
@Table(name = "STORE_PAY_RETURN_ORDER")
public class PayReturnOrder extends IdEntity {
    private  String return_code;//支付编号 系统支付
    private  String return_msg;//关联编号
    private  String appid;//微信分配的公众账号ID（企业号corpid即为此appId）
    private  String mch_id;//微信支付分配的商户号
    private  String device_info;//微信支付分配的终端设备号，
    private  String nonce_str;//随机字符串，不长于32位
    private  String sign;//	签名，详见签名算法
    private  String sign_type;//签名类型，目前支持HMAC-SHA256和MD5，默认为MD5
    private  String result_code;//SUCCESS/FAIL
    private  String err_code;//错误返回的信息描述
    private  String err_code_des;//错误返回的信息描述
    private  String openid;//用户在商户appid下的唯一标识
    private  String is_subscribe;//用户是否关注公众账号，Y-关注，N-未关注，仅在公众账号类型支付有效
    private  String trade_type;//JSAPI、NATIVE、APP
    private  String bank_type;//银行类型，采用字符串类型的银行标识，银行类型见银行列表
    private  String total_fee;//订单总金额，单位为分
    private  String settlement_total_fee;//应结订单金额=订单金额-非充值代金券金额，应结订单金额<=订单金额。
    //private  String fee_type;//货币类型，符合ISO4217标准的三位字母代码，默认人民币：CNY，其他值列表详见货币类型
    //private  String cash_fee;//现金支付金额订单现金支付金额，详见支付金额
   // private  String cash_fee_type;//货币类型，符合ISO4217标准的三位字母代码，默认人民币：CNY，其他值列表详见货币类型
   // private  String coupon_fee;//	代金券金额<=订单金额，订单金额-代金券金额=现金支付金额，详见支付金额
   // private  String coupon_count;//代金券使用数量
   // private  String coupon_id_$n;//CASH--充值代金券  NO_CASH---非充值代金券  订单使用代金券时有返回（取值：CASH、NO_CASH）。$n为下标,从0开始编号，举例：coupon_type_0
   //  private  String coupon_type_$n;//代金券ID,$n为下标，从0开始编号
   // private  String coupon_id_$n;//单个代金券支付金额,$n为下标，从0开始编号
    private  String transaction_id;//微信支付订单号
    private  String out_trade_no;//商户系统的订单号，与请求一致。
//    private  String attach;//商家数据包，原样返回
    private  String time_end;// 支付完成时间，格式为yyyyMMddHHmmss，如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则

    public String getReturn_code() {
        return return_code;
    }

    public void setReturn_code(String return_code) {
        this.return_code = return_code;
    }

    public String getReturn_msg() {
        return return_msg;
    }

    public void setReturn_msg(String return_msg) {
        this.return_msg = return_msg;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getSign_type() {
        return sign_type;
    }

    public void setSign_type(String sign_type) {
        this.sign_type = sign_type;
    }

    public String getResult_code() {
        return result_code;
    }

    public void setResult_code(String result_code) {
        this.result_code = result_code;
    }

    public String getErr_code() {
        return err_code;
    }

    public void setErr_code(String err_code) {
        this.err_code = err_code;
    }

    public String getErr_code_des() {
        return err_code_des;
    }

    public void setErr_code_des(String err_code_des) {
        this.err_code_des = err_code_des;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getIs_subscribe() {
        return is_subscribe;
    }

    public void setIs_subscribe(String is_subscribe) {
        this.is_subscribe = is_subscribe;
    }

    public String getTrade_type() {
        return trade_type;
    }

    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }

    public String getBank_type() {
        return bank_type;
    }

    public void setBank_type(String bank_type) {
        this.bank_type = bank_type;
    }

    public String getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(String total_fee) {
        this.total_fee = total_fee;
    }

    public String getSettlement_total_fee() {
        return settlement_total_fee;
    }

    public void setSettlement_total_fee(String settlement_total_fee) {
        this.settlement_total_fee = settlement_total_fee;
    }

    public String getTransaction_id() {
        return transaction_id;
    }

    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getTime_end() {
        return time_end;
    }

    public void setTime_end(String time_end) {
        this.time_end = time_end;
    }

    public PayReturnOrder getWxRereturn(String xml){
        XStream xStream = new XStream(new DomDriver());
        xStream.alias("xml", this.getClass());
        // 设置成员的别名
        xStream.aliasField("return_code", this.getClass(), "return_code");
        xStream.aliasField("return_msg", this.getClass(), "return_msg");
        PayReturnOrder temp = (PayReturnOrder) xStream.fromXML(xml);

        XStream newStream = new XStream(new DomDriver());
        newStream.alias("xml", this.getClass());
        if(temp.getReturn_code().equals("SUCCESS")){//返回成功
            newStream.aliasField("appid", this.getClass(), "appid");
            newStream.aliasField("mch_id", this.getClass(), "mch_id");
            newStream.aliasField("nonce_str", this.getClass(), "nonce_str");
            newStream.aliasField("sign", this.getClass(), "sign");
            newStream.aliasField("result_code", this.getClass(), "result_code");
            newStream.aliasField("openid", this.getClass(), "openid");
            newStream.aliasField("trade_type", this.getClass(), "trade_type");
            newStream.aliasField("bank_type", this.getClass(), "bank_type");
            newStream.aliasField("total_fee", this.getClass(), "total_fee");
            newStream.aliasField("cash_fee", this.getClass(), "cash_fee");
            newStream.aliasField("transaction_id", this.getClass(), "transaction_id");
            newStream.aliasField("out_trade_no", this.getClass(), "out_trade_no");
            newStream.aliasField("time_end", this.getClass(), "time_end");
        }
        PayReturnOrder authPush=(PayReturnOrder) newStream.fromXML(xml);
        return authPush;
    }

}
